package com.hzzh.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hzzh.dao.MeetingParticipantsDAO;
import com.hzzh.service.MeetingRoomService;
import com.hzzh.vo.Meeting;

/**
 * Servlet implementation class MyNotificationServlet
 */
@WebServlet("/MyNotificationServlet")
public class MyNotificationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyNotificationServlet() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取session中的employeeid
		HttpSession session=request.getSession();
		int participantsid=(Integer) session.getAttribute("employeeid");
		
		
		MeetingParticipantsDAO dao=new MeetingParticipantsDAO();
		//查询某员工最近七天参加的所有会议
		List<Meeting> meetingsList=dao.selectAllNewMeetings(participantsid);
		//查询某员工要参加，状态为取消的会议
		List<Meeting> canceledMeetings=dao.selectAllCanceledMeetings(participantsid);
        
		MeetingRoomService roomService=new MeetingRoomService();
		
		List<String>  roomsNameList=new ArrayList<String>();
		for(Meeting m:meetingsList){
			roomsNameList.add(roomService.viewOneMeetingRoom(m.getRoomid()).getRoomname());
		}
		
		Map<Meeting,String> meetingsMap=new HashMap<Meeting,String>();
		
		for(int i=0;i<meetingsList.size();i++){
			meetingsMap.put(meetingsList.get(i), roomsNameList.get(i));
		}
		
		request.setAttribute("meetingsMap", meetingsMap);
		
		List<String>  cancelRoomNameList=new ArrayList<String>();
		for(Meeting m:canceledMeetings){
			cancelRoomNameList.add(roomService.viewOneMeetingRoom(m.getRoomid()).getRoomname());
		}
		
		Map<Meeting,String> cancelMeetingsMap=new HashMap<Meeting,String>();
		
		for(int i=0;i<canceledMeetings.size();i++){
			cancelMeetingsMap.put(canceledMeetings.get(i),cancelRoomNameList.get(i));
		}
		request.setAttribute("cancelMeetingsMap", cancelMeetingsMap);
		
		request.getRequestDispatcher("mynotification.jsp").forward(request, response);
		
	}

}
